# = test.blogs.7.rb - My Blogs, Blog Feed Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# This will test the blog feeds
#

    require 'watir'
    include Watir
    require 'test/unit'
    require 'watir/WindowHelper'
    require '../watir.config.rb'
    
	class TC_BlogFeeds_test < Test::Unit::TestCase
	  def startup			
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
  
    def test_06_navigateToBlogs
      assert(ie.link(:text, 'Blogs').exists?)
      ie.link(:text, 'Blogs').click
    end
    
    def test_07_verifyLinksOnBlogsPage
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Home').exists?)
      assert(ie.link(:text, 'Blogs').exists?)
      assert(ie.link(:text, 'Forums').exists?)
      assert(ie.link(:text, 'Photos').exists?)
      assert(ie.link(:text, 'Downloads').exists?)
      #assert(ie.link(:text, 'Comments').exists?)
      assert(ie.link(:text, 'Blogging').exists?)
      assert(ie.link(:text, 'Browse All Tags').exists?)
      assert(ie.link(:text, 'RSS Syndication').exists?)
      assert(ie.link(:text, 'Opml').exists?)
      assert(ie.link(:text, 'Blogs on this Site').exists?)
      
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
      ie.text_field(:id, /TitleBarSearchText$/).set('okUOfZbOK')
      assert(ie.text_field(:id, /TitleBarSearchText$/).verify_contains('okUOfZbOK'))
      
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
      ie.text_field(:id, /TitleBarSearchText$/).set('jLWdN')
      assert(ie.text_field(:id, /TitleBarSearchText$/).verify_contains('jLWdN'))
      
      # Changes made 
      #assert(ie.text_field(:id, /SearchBox$/).exists?)
      #ie.text_field(:id, /SearchBox$/).set('jLWdN')
      #assert(ie.text_field(:id, /SearchBox$/).verify_contains('jLWdN'))
    end
    
    def test_08_verifyRssSyndication
      assert(ie.link(:text, 'RSS Syndication').exists?)
      ie.link(:text, 'RSS Syndication').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)

      assert_equal 'http://en.wikipedia.org/wiki/RSS_(file_format)', ie.link(:text, 'Wikipedia').href
    end
    
    def test_09_verifyOpml
      ie.goto($SITE_URL)
      ie.link(:text, 'Blogs').click
      
      assert(ie.link(:text, 'Opml').exists?)
      ie.link(:text, 'Opml').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/OPML', ie.link(:text, 'Wikipedia').href
    end
    
    def test_10_verifyBlogsOnSite
      ie.goto($SITE_URL)
      ie.link(:text, 'Blogs').click
      
      assert(ie.link(:text, 'Blogs on this Site').exists?)
      ie.link(:text, 'Blogs on this Site').click
      
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Home').exists?)
      assert(ie.link(:text, 'Blogs').exists?)
      assert(ie.link(:text, 'Forums').exists?)
      assert(ie.link(:text, 'Photos').exists?)
      assert(ie.link(:text, 'Downloads').exists?)
      #assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:text, 'Blogging').exists?)
      assert(ie.link(:text, 'Browse All Tags').exists?)
      assert(ie.link(:text, 'RSS Syndication').exists?)
      assert(ie.link(:text, 'Opml').exists?)
      assert(ie.link(:text, 'Blogs on this Site').exists?)

      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
      ie.text_field(:id, /TitleBarSearchText$/).set('EgyUZhNOaT')
      assert(ie.text_field(:id, /TitleBarSearchText$/).verify_contains('EgyUZhNOaT'))
    end
    
    def test_11_verifyBloggersRssSyndication
      assert(ie.link(:text, 'RSS Syndication').exists?)
      ie.link(:text, 'RSS Syndication').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)

      assert_equal 'http://en.wikipedia.org/wiki/RSS_(file_format)', ie.link(:text, 'Wikipedia').href
    end
    
    def test_12_verifyBloggersOpml
      ie.goto($SITE_URL + 'blogs/Bloggers.aspx')
      
      assert(ie.link(:text, 'Opml').exists?)
      ie.link(:text, 'Opml').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/OPML', ie.link(:text, 'Wikipedia').href
    end
    
    def test_13_verifyIndividualBlog
      ie.goto($SITE_URL + 'blogs/Bloggers.aspx')
      assert(ie.contains_text('Blogs on this site'))
      
      ie.goto($SITE_URL + 'blogs/sample_weblog/default.aspx')
      
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Home').exists?)
      assert(ie.link(:text, 'Blogs').exists?)
      assert(ie.link(:text, 'Forums').exists?)
      assert(ie.link(:text, 'Photos').exists?)
      assert(ie.link(:text, 'Downloads').exists?)
      assert(ie.link(:text, 'Blogging').exists?)
      assert(ie.link(:text, 'RSS').exists?)
      assert(ie.link(:text, 'Atom').exists?)
    end
    
    def test_14_verifyIndividualBlogRss
      assert(ie.link(:text, 'RSS').exists?)
      ie.link(:text, 'RSS').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/RSS_(file_format)', ie.link(:text, 'Wikipedia').href
    end
    
    def test_15_verifyIndividualBlogAtom
      ie.goto($SITE_URL + 'blogs/Bloggers.aspx')
      assert(ie.contains_text('Blogs on this site'))
      
      ie.goto($SITE_URL + 'blogs/sample_weblog/default.aspx')
      
      assert(ie.link(:text, 'Atom').exists?)
      ie.link(:text, 'Atom').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/Atom_(standard)', ie.link(:text, 'Wikipedia').href
    end
    
    def test_16_verifyIndividualPost
      ie.goto($SITE_URL + 'blogs/Bloggers.aspx')
      assert(ie.contains_text('Blogs on this site'))
      
      ie.goto($SITE_URL + 'blogs/sample_weblog/default.aspx')
      
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)
      ie.link(:text, 'Welcome to Community Server Blogs!').click
      
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Home').exists?)
      assert(ie.link(:text, 'Blogs').exists?)
      assert(ie.link(:text, 'Forums').exists?)
      assert(ie.link(:text, 'Photos').exists?)
      assert(ie.link(:text, 'Downloads').exists?)
      assert(ie.link(:text, 'Blogging').exists?)
      assert(ie.link(:text, 'RSS').exists?)
      assert(ie.link(:text, 'Atom').exists?)
    end
    
    def test_17_verifyIndividualPostRss
      assert(ie.link(:text, 'RSS').exists?)
      ie.link(:text, 'RSS').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/RSS_(file_format)', ie.link(:text, 'Wikipedia').href
    end
    
    def test_18_verifyIndividualAtom
      ie.goto($SITE_URL + 'blogs/Bloggers.aspx')
      assert(ie.contains_text('Blogs on this site'))
      
      ie.goto($SITE_URL + 'blogs/sample_weblog/default.aspx')
      
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)
      ie.link(:text, 'Welcome to Community Server Blogs!').click
      
      assert(ie.link(:text, 'Atom').exists?)
      ie.link(:text, 'Atom').click
      
      assert(ie.link(:text, 'Wikipedia').exists?)
      assert(ie.link(:text, 'Welcome to Community Server Blogs!').exists?)
      assert_equal 'http://en.wikipedia.org/wiki/Atom_(standard)', ie.link(:text, 'Wikipedia').href
      ie.goto($SITE_URL)
    end
  
    def test_99_closeIE
      ie.close
    end
  end